<?php
namespace App\Services;

use App\Repositories\StaffRepository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class StaffService
{
    private $staffRepository;

    public function __construct(StaffRepository $staffRepository)
    {
        $this->staffRepository = $staffRepository;
    }

    public function createStaff($uid, Request $request)
    {
        $rules = $this->staffRepository->getCreateStaffMustParamRules();

        Validator::make($request->all(), $rules)->validate();

        $userStaffParams = $this->staffRepository->getCreateUserStaffReloadNeedParams();
        $userStaffOptionParams = $this->staffRepository->getCreateUserStaffOptionReloadNeedParams();

        $userStaffOptionData = $userStaffData = ['uid' => $uid];
        foreach ($userStaffParams as $item) {
            $userStaffData[$item] = $request->$item;
        }
        foreach ($userStaffOptionParams as $item) {
            if(isset($request->$item)) $userStaffOptionData[$item] = $request->$item;
        }

        $this->staffRepository->add($uid, $userStaffData, $userStaffOptionData);
    }

}